from typing import Mapping
import requests
import execjs
import jsonpath
class qxx():
    def __init__(self):
        self.url ='https://www.qcc.com/api/search/searchMulti'
        self.headers={
            'accept': 'application/json, text/plain, */*',
            'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'cache-control': 'no-cache',
            'content-type': 'application/json',
            # result['i'] : result['u'],
            'origin': 'https://www.qcc.com',
            'pragma': 'no-cache',
            'priority': 'u=1, i',
            'referer': 'https://www.qcc.com/web/search?key=%E4%B8%9C%E8%BD%AF',
            'sec-ch-ua': '"Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0',
            'x-pid': 'bb3763e5d17d90e2d10d5c8c0e20fd67',
            'x-requested-with': 'XMLHttpRequest',
            # 'cookie': 'QCCSESSID=8a4a2b5be134d72b522a664a36; qcc_did=753e8ea2-da8a-4847-900a-1c71d5690342; UM_distinctid=1966695eb091388-033e93f82ea8648-4c657b58-1bcab9-1966695eb0a2639; tfstk=gIPs91xRBhx_Skt3SGQEPZAVCehbco1rcEgYrrdwkfh9DnU-YVPNjrnbcko3cxbi0mnb0reN8_5zSPcmMnsPa_5rkNv0fnhxHZdKSq_EWB7D1xcmMgSEC7el-jqT5gbLMyQIuqR96on9vDnnWqhxXxKpp4nKDjExDBnKy4ixWddARynnkjnYDjHHu3ufuca1Sguc2QJSEPnBMIFOiAi5VD3nRWgtC0HKAIe_OVMs2PFW1cTqJWPIUv8VEXUuLl3IN6JtwywYV8EcUpc_kREmdljHdDyLsrnxCEduRzaTeXFVkUDQvqM-MvTvMyGicYPtw_KI-JUaH5q6lI3g_7kjqv_vixlLaYe8fEbuJf3YmYVVqCmTkzVuUb1eBbUQHuwf4xdrV-U6heMkG2iPRw9DnTryKyIJEJ8SB20sOw_BfXHt-2iPRw9DnA3n8p_CRhGd.; CNZZDATA1254842228=415518209-1745477823-https%253A%252F%252Fcn.bing.com%252F%7C1745497103; acw_tc=1a0c39d317454991329231408e0069f1cfa09cf15bbe58778b13d66fd5d550',
        }
        self.cookies = {
            'QCCSESSID': '8a4a2b5be134d72b522a664a36',
            'qcc_did': '753e8ea2-da8a-4847-900a-1c71d5690342',
            'UM_distinctid': '1966695eb091388-033e93f82ea8648-4c657b58-1bcab9-1966695eb0a2639',
            'tfstk': 'gIPs91xRBhx_Skt3SGQEPZAVCehbco1rcEgYrrdwkfh9DnU-YVPNjrnbcko3cxbi0mnb0reN8_5zSPcmMnsPa_5rkNv0fnhxHZdKSq_EWB7D1xcmMgSEC7el-jqT5gbLMyQIuqR96on9vDnnWqhxXxKpp4nKDjExDBnKy4ixWddARynnkjnYDjHHu3ufuca1Sguc2QJSEPnBMIFOiAi5VD3nRWgtC0HKAIe_OVMs2PFW1cTqJWPIUv8VEXUuLl3IN6JtwywYV8EcUpc_kREmdljHdDyLsrnxCEduRzaTeXFVkUDQvqM-MvTvMyGicYPtw_KI-JUaH5q6lI3g_7kjqv_vixlLaYe8fEbuJf3YmYVVqCmTkzVuUb1eBbUQHuwf4xdrV-U6heMkG2iPRw9DnTryKyIJEJ8SB20sOw_BfXHt-2iPRw9DnA3n8p_CRhGd.',
            'CNZZDATA1254842228': '415518209-1745477823-https%253A%252F%252Fcn.bing.com%252F%7C1745497103',
            'acw_tc': '1a0c39d317454991329231408e0069f1cfa09cf15bbe58778b13d66fd5d550',
        }
        self.data =  {
                'searchKey': '拼多多',
                'pageIndex': 4,
                'pageSize': 20,
            }
        self.js = execjs.compile(open('qcchmac.js', 'r', encoding='utf-8').read())
        self.proxies = {
        "http": "http://127.0.0.1:7890",
        "https": "http://127.0.0.1:7890",
        }
    def request_data(self):
        js = self.js.call('get_header', self.data)
        print(js)
        self.headers[js['i']] = js['u']
        result = requests.post(self.url, cookies=self.cookies, headers=self.headers, json=self.data,proxies=self.proxies)
        # print(result.json())
        return result.json()
if __name__ == '__main__':
    qcc = qxx()
    res=qcc.request_data()
    print(type(res))
    print(res)
    name = jsonpath.jsonpath(res, '$.Result.Name')
    print(name)